// pages/activityLeave/activityLeave.js
import {courseLeave} from "../../services/courseReq";

Page({

    /**
     * 页面的初始数据
     */
    data: {
        titleValue: '',
        commentValue: '',
        teachingscheduleId: '',
        courseabsentContent: ''

    },
    handleCommentChange(e) {
        let {value} = e.detail;
        this.setData({
            courseabsentContent: value
        })
    },
    handleAddNow() {
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options)
        this.setData({
            teachingscheduleId: options.id
        })
    },
    handleSubmit() {

        let teachingScheduleId = ~~this.data.teachingscheduleId;
        let courseabsentContent = this.data.courseabsentContent;
        if (!courseabsentContent) return wx.showToast({
            title: "请输入请假理由",
            icon: "error"
        })
        let params = {
            courseabsentContent,
            teachingScheduleId
        }
        wx.showLoading({
            title: "Loading...."
        })
        courseLeave(params, res => {
            // console.log(res)
            if (res.data.code !== 0) return wx.showToast({
                title: res.data.msg,
                icon: "error"
            })

            return wx.showToast({
                title: "请假成功",
                icon: "success"
            })
            // wx.navigateBack()
        })
    },
})
